
* Code for generating residuals from the gravity model
* 
* Model A1 in the Appendix


xtreg imports st1_gdp st2_gdp st1_income st2_income /*colony ln_dist comcol comlang_off contig*/ i.year, fe i(dyadid_un)
estimates store m1
*keep if e(sample)
predict xbu_log, xbu /*predicted trade including dyadic component*/
gen xbu =exp(xbu_log)
predict e_log , e /*residual of trade */
gen e = exp(e_log)

reg imports st1_gdp st2_gdp st1_income st2_income colony ln_dist comcol comlang_off contig i.year,
 estimates store m2
 esttab m1 m2  using gravitytable.tex, r2 obslast starlevels(* .1 ** .05 *** .01) cells(b(star fmt(%9.2f)) se(par fmt(%9.2f))) replace
 
predict e2_log , resid

corr e_log e2_log
